using System;
using UnityEngine;

[Serializable]
public struct PhysicsMaterialMultiply
{
	[Tooltip("Материал физ.фигуры")]
	public PhysicsMaterial2D material;

	[Tooltip("Множитель для снижения урона")]
	public float scaleFirst;

	[Tooltip("Множитель для снижения урона")]
	public float scaleThrough;

	public static float GetScaleDamage(PhysicsMaterial2D materialHit, PhysicsMaterialMultiply[] listMultiply, bool isFirstHit, float defaultValue)
	{
		for (int i = 0; i < listMultiply.Length; i++)
		{
			if (listMultiply[i].material.name == materialHit.name)
			{
				if (isFirstHit)
				{
					return listMultiply[i].scaleFirst;
				}
				return listMultiply[i].scaleThrough;
			}
		}
		return defaultValue;
	}

	public static float GetScaleDamage(PhysicsMaterial2D materialHit, PhysicsMaterialMultiply[] listMultiply, HitBullet lastBulletHit, ShotBullet currentBullet)
	{
		if (currentBullet.id == lastBulletHit.bullet.id)
		{
			return lastBulletHit.scaleDamage * GetScaleDamage(lastBulletHit.collider.sharedMaterial, listMultiply, isFirstHit: false, 1f) * GetScaleDamage(materialHit, listMultiply, isFirstHit: true, 1f);
		}
		return GetScaleDamage(materialHit, listMultiply, isFirstHit: true, 1f);
	}

	public static float GetScaleDamage(PhysicsMaterial2D materialHit, PhysicsMaterialMultiply[] listMultiply)
	{
		for (int i = 0; i < listMultiply.Length; i++)
		{
			if (listMultiply[i].material.name == materialHit.name)
			{
				return listMultiply[i].scaleFirst;
			}
		}
		return 0f;
	}

	public static bool StopBullet(PhysicsMaterial2D materialHit, PhysicsMaterialMultiply[] list)
	{
		for (int i = 0; i < list.Length; i++)
		{
			if (list[i].material.name == materialHit.name)
			{
				return list[i].scaleThrough == 0f;
			}
		}
		return false;
	}
}
